<?php

namespace App\Http\Controllers;

use App\Common\Curl;
use App\Http\Controllers\Traits\TransFormer;
use App\Http\Requests\MessRequest;
use App\Services\InjuryService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;

class InjuryController extends Controller
{
    use TransFormer;

    protected $service;
    protected $mess;
    public function __construct(InjuryService $service,MessRequest $mess)
    {
        $this->service = $service;
        $this->mess = $mess;
    }

    /**
     * 初次检伤-添加-修改
     * @param Request $request
     * @return array
     */
    public function saveOne(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->saveOne();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1002001,$validator->errors()->first());
        }
        $result = $this->service->saveOne($data);
        return $this->transFormer(200,'成功',$result);
    }

    public function getOneMess()
    {
        
    }

    /**
     * 二次检伤-伤情特点-保存/更新
     * @param Request $request
     * @return array
     */
    public function saveTwoTrait(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->saveTwoTrait();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1002003,$validator->errors()->first());
        }
        $result = $this->service->saveTwoTrait($data);
        return $this->transFormer(200,'成功',$result);
    }


    /**
     * 二次检伤-现场检伤-保存/更新
     * @param Request $request
     * @return array
     */
    public function saveTwoSceneB(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->saveTwoSceneB();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1002004,$validator->errors()->first());
        }
        $result = $this->service->saveTwoSceneB($data);
        return $this->transFormer(200,'成功',$result);
    }

    /**
     * 获取二次检伤综合信息
     * @param Request $request
     * @return array
     */
    public function getTwoInjuryInfo(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->patientId();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1002006,$validator->errors()->first());
        }
        $result = $this->service->getTwoInjuryInfo($data);
        return $this->transFormer(200,'成功',$result);
    }

    /**
     * 获取二次检伤 伤情特点 详情
     * @param Request $request
     * @return array
     */
    public function getTwoInjuryTrait(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->patientId();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1002007,$validator->errors()->first());
        }
        $result = $this->service->getTwoInjuryTrait($data);
        return $this->transFormer(200,'成功',$result);
    }

    /**
     * 获取二次检伤 现场验伤 详情
     * @param Request $request
     * @return array
     */
    public function getTwoInjuryScene(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->patientId();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1002008,$validator->errors()->first());
        }
        $result = $this->service->getTwoInjuryScene($data);
        return $this->transFormer(200,'成功',$result);
    }

    /**
     * 获取 检伤信息
     * @param Request $request
     * @return array
     */
    public function getInjuryMess(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->patientId();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1002010,$validator->errors()->first());
        }
        $result = $this->service->getInjuryMess($data);
        return $this->transFormer(200,'成功',$result);
    }

    /**
     * 获取 初次检伤信息
     * @param Request $request
     * @return array
     */
    public function getOneInjury(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->patientId();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1002011,$validator->errors()->first());
        }
        $result = $this->service->getOneInjury($data);
        return $this->transFormer(200,'成功',$result);
    }

    /**
     * 获取 初次检伤信息
     * @param Request $request
     * @return array
     */
    public function setLevelMess(Request $request)
    {
        $data = $request->all();
        $rules = $this->mess->setLevelMess();
        $validator = Validator::make($data,$rules['rules'],[],$rules['rName']);
        if($validator -> fails()){
            return $this->transFormer(1002015,$validator->errors()->first());
        }
        $result = $this->service->setLevelMess($data);
        return $this->transFormer(200,'成功',$result);
    }
}
